package db;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import beans.Person;
import beans.TaskMetrics;

public class TaskDAO {
	
	public static List getTaskMetricsForProject(int projectId) {
		try {
			Connection c = DataUtils.getDBConnection();
			
			PreparedStatement st = c.prepareStatement(SQL.map.get("STASKMETRICS.sql").toString());
			st.setInt(1, projectId);
			
			ResultSet rs = st.executeQuery();
		    
		    List taskMetrics = new ArrayList();
		    
		    while (rs.next()) {
		    
		    	int taskId = rs.getInt("TASK_ID"); 
		    	String status = rs.getString("STATUS");
		    	int sequence   = rs.getInt("SEQUENCE");
		    	String description   = rs.getString("DESCRIPTION");
		    	int scount   = rs.getInt("SCOUNT");
		    	int rcount   = rs.getInt("RCOUNT");
		    	
		    	taskMetrics.add(new TaskMetrics(taskId, status, sequence, description, scount, rcount));
		    }
		    
		    rs.close();
		    st.close();
		    
		    return taskMetrics;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static void addSkill(int taskId, int skillId, int level,
			String startDate, String endDate, int percent) {
		try {
			Connection c = DataUtils.getDBConnection();
		
			PreparedStatement st = c.prepareStatement(SQL.map.get("ITASKNEEDSSKILL.sql").toString());
			st.setInt(1, taskId);
			st.setInt(2, skillId);
			st.setInt(3, level);
			st.setInt(4, percent);
			st.setDate(5, Date.valueOf(startDate));
			st.setDate(6, Date.valueOf(endDate));
			
			st.executeUpdate();
			
		    st.close();
		    
		    return;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}


}
